package com.yf.dxs.wo.req;

import cn.hutool.http.HttpUtil;
import com.yf.dxs.wo.config.WoProperties;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriBuilder;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

@Component
public class WoRequest {

    @Resource
    private WoProperties woProperties;

    public static final String ACCESS_TOKEN_URL = "https://dopen.weimob.com/fuwu/b/oauth2/token?grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}&shop_id={shop_id}&shop_type={shop_type}";

    public  String getAccessToken(){
      String uri =   UriComponentsBuilder.fromHttpUrl(ACCESS_TOKEN_URL).buildAndExpand(woProperties.clientId,woProperties.clientSecret,woProperties.shopId,woProperties.shopType).toUriString();
      String res = HttpUtil.post(uri,"");
      return res;
    }

}
